package org.ht.util;

import java.util.ArrayList;
import java.util.List;

public class StringUtil {
	public static boolean isNumeric(String str){
		  for (int i = str.length();--i>=0;){   
		   if (!Character.isDigit(str.charAt(i))){
		    return false;
		   }
		  }
		  return true;
		 }
	
	// 过滤数字
	public static List<String> filterNum(List<String> urls){
		List<String> result = new ArrayList<String>();
		for (String url:urls){
			if (!isNumeric(url)){
				result.add(url);
			}
		}
		return result;
	}
	
	// 过滤路径
	public static List<String> filterUrl(List<String> urls){
		List<String> result = new ArrayList<String>();
		for (String url:urls){
			if (isNumeric(url)){
				result.add(url);
			}
		}
		return result;
	}
	
	public static List<String> StringToList(String srcString, String delimit) {
		String[] tmpListStrings = srcString.split(delimit);
		
		ArrayList<String> als=new ArrayList<String>(0);
		for(String s : tmpListStrings){
			als.add(s);
		}
		
		return als;
	}
	
	public static String ListToString(List<String> list, String delimit) {
		String tmpString = "";
		for (String s : list) {
			tmpString += s + delimit;
		}

		return tmpString;
	}
	
	public static String filterNum(String srcString){
		return ListToString(filterNum(StringToList(srcString,";")),";");
	}
	
	public static String filterUrl(String srcString){
		return ListToString(filterUrl(StringToList(srcString,";")),";");
	}
}
